package cn.icanci.loopstack.bic.biz.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.icanci.loopstack.bic.biz.dts.GraphDtsServiceProxy;
import cn.icanci.loopstack.bic.biz.mapper.UnitViewTreeMapper;
import cn.icanci.loopstack.bic.biz.service.UnitViewTreeService;
import cn.icanci.loopstack.bic.common.model.graph.UnitViewTreeVO;
import cn.icanci.loopstack.bic.dal.mongo.common.PageList;
import cn.icanci.loopstack.bic.dal.mongo.daointerface.UnitViewTreeDAO;
import cn.icanci.loopstack.bic.dal.mongo.dateobject.UnitViewTreeDO;

/**
 * @author icanci
 * @since 1.0 Created in 2023/09/17 15:45
 */
@Service
public class UnitViewTreeServiceImpl implements UnitViewTreeService {

    @Resource
    private UnitViewTreeDAO      unitViewTreeDAO;
    @Resource
    private UnitViewTreeMapper   unitViewTreeMapper;
    @Resource
    private GraphDtsServiceProxy graphDtsServiceProxy;

    @Override
    public List<UnitViewTreeVO> queryAll() {
        return unitViewTreeMapper.dos2vos(unitViewTreeDAO.queryAll());
    }

    @Override
    public void save(UnitViewTreeVO unitViewTreeVO) {
        // TODO 日志记录
        if (doInsert(unitViewTreeVO)) {
            UnitViewTreeDO insert = unitViewTreeMapper.vo2do(unitViewTreeVO);
            unitViewTreeDAO.insert(insert);
            unitViewTreeVO = unitViewTreeMapper.do2vo(insert);
        } else {
            unitViewTreeDAO.update(unitViewTreeMapper.vo2do(unitViewTreeVO));
        }
        graphDtsServiceProxy.dtsUnitViewTree(unitViewTreeVO);
    }

    @Override
    public UnitViewTreeVO queryById(String id) {
        return unitViewTreeMapper.do2vo(unitViewTreeDAO.queryOneById(id));
    }

    @Override
    public PageList<UnitViewTreeVO> queryPage(UnitViewTreeVO unitViewTreeVO, int pageNum, int pageSize) {
        PageList<UnitViewTreeDO> pageQuery = unitViewTreeDAO.pageQuery(unitViewTreeMapper.vo2do(unitViewTreeVO), pageNum, pageSize);
        return new PageList<>(unitViewTreeMapper.dos2vos(pageQuery.getData()), pageQuery.getPaginator());
    }

    @Override
    public UnitViewTreeVO queryBySystemUuidAndUseCaseUuid(String systemUuid, String useCaseUuid) {
        return unitViewTreeMapper.do2vo(unitViewTreeDAO.queryBySystemUuidAndUseCaseUuid(systemUuid, useCaseUuid));
    }
}
